// ************************* 78 character ruler *****************************
//
// Title:       SoftwareFileActivate.c
// Purpose:     A short description of the implementation.
//
// Created on:  2012-4-25 at 15:55:33 by luh.
// Copyright:   dafda. All Rights Reserved.
//
// ************************* 78 character ruler *****************************

#include "RFBB.h"         
#include <utility.h>
#include "stdio.h"
#include "PsuContorl.h"
//CALI DIR1 OMP1 FDR1 CLI1 FIL1 DCF1 MOD1 TIM1 DAC1 HWI1 FEC1 MON1 EXT1
char g_szSoftwareActivateCmd[BUFFER_SIZE_256] = "flash -a CALI DIR1 OMP1 FDR1 CLI1 FIL1 DCF1 MOD1 TIM1 DAC1 HWI1 FEC1 MON1 EXT1 CSS1";
//char g_szBBBoardRetCmd[BUFFER_SIZE_64] = "Mcu -r 1 6";
/**************************************************************************************************
  Function:            SoftwareFileActivate
  Description:        The purpose of Check that transfering software to BB board SDRAM and downloading software is ok
  Calls:                none
  Called By:          dll
  Table Accessed:  none
  Table Updated:   none
  Input:                none
  Output:              error code
  Return:              none
  Test Case ID:     SW File activater
  Used Command:  g_szSoftwareActivateCmd,g_szBBBoardRetCmd
**************************************************************************************************/

void __decldllexp TX_TEST SoftwareFileActivate(tTestData *testData, tTestError *testError)
{    
    ErrMsg errMsg = {'\0'};
    ERRORINFO errorInfo;
    ErrMsg szLogMsg;
    CAObjHandle hStepName = 0;
    char* pszStepName = NULL;
    char kszShmonAgent[BUFFER_SIZE_256] ={'\0'};
    char szReturnString[BUF_SIZE_32K + 1] = {'\0'};
	char szTemp[512] = {'\0'};
	
    int error = 0;
    int i=0;
    int iPassFail= 1;
    int iReturn=0;
    int iPipeNum = 0;
    int iIQNum = 0;
    unsigned int iShiftBit = 0;
    int iFbNum = 0;
    int iByte = 0;
    //////////////////////////////////////////////////////////////////////////   
    // Resolve StepName 
    tsErrChk(TS_SeqContextGetProperty (testData->seqContextCVI, &errorInfo, 
                               TS_SeqContextStep, CAVT_OBJHANDLE, 
                               &hStepName));
    tsErrChk(TS_StepGetProperty (hStepName, &errorInfo, TS_StepName, CAVT_CSTRING, 
                         &pszStepName));

    sprintf( szLogMsg, TEST_NAME_EVENT_FMTSTR, pszStepName );
    ErrChk( EELog_INEventLogLogEvent( g_hEventLog, NULL, szLogMsg ) );

    // Post message to GUI
    tsErrChk(TS_ThreadPostUIMessageEx (g_hThreadPostUIMessage, NULL,
                               TS_UIMsg_ProgressText, 0.0,
                               pszStepName, 0, VTRUE));
    
    /******************************************test ***************************************************/
	g_hShellCommand = RfbbInetTelnetOpen (g_szDUTIP, g_iShellCommandPort, 0);  


    sprintf(kszShmonAgent,g_szSoftwareActivateCmd);
    if(ShellCommandWriteReadUntil(kszShmonAgent,"StatusOk", szReturnString,5000,1) != 0) 
    {
        sprintf(errMsg, "OseWriteReadUntil() - failed");
        iPassFail = 0;
        error = -1;
        goto Error;
    }
    

    Delay(5);  
    
Error: 

#if(ON_OFF != SIMU_VERS)

    if(iPassFail == PASS) 
    {
        testData->result = PASS;
    }
    else 
    {
        testData->result = FAIL;
    }

    //FREE RESOURCES
    InetTelnetClose(g_hShellCommand);
    
    CA_DISCARD_OBJ( hStepName );
	CA_FREE( pszStepName );
   
	//If an error occurred, set the error flag to cause a run-time error in TestStand.
    if(error < 0)
    {
        testError->errorFlag = TRUE;
        testError->errorCode = error;
        testData->replaceStringFuncPtr(&testError->errorMessage, errMsg);
    }
    
#else
    testData->result = PASS;
#endif
    // Clear message from GUI
    TS_ThreadPostUIMessageEx (g_hThreadPostUIMessage, NULL,
                                  TS_UIMsg_ProgressText, 0.0, " ", 0, VTRUE);
    
    return;
			 
}
   

   



// ************************* 78 character ruler *****************************
//                           End of source file
// **************************************************************************


